package com.lczc.soa.controller;

import com.lczc.soa.domain.*;
import com.lczc.soa.service.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/Syslog")
public class SyslogController {
    @Autowired
    private SyslogService logService;

    @RequestMapping("/list")
    public String SyslogList() {
        return "log_list";
    }


    @GetMapping("/api/search")
    @ResponseBody
    public SearchSyslogResponse searchSyslogResponse(@RequestParam("pageNum") Integer pageNum,
                                                 @RequestParam("pageSize") Integer pageSize) {

        SearchSyslogResponse syslog = logService.findAllSyslog(pageNum, pageSize);
        return syslog;
    }

    @GetMapping("/api/searchLike")
    @ResponseBody
    public SearchSyslogResponse searchSyslogResponseLike(@RequestParam("keywords") String keywords,
                                                     @RequestParam("pageNum") Integer pageNum,
                                                     @RequestParam("pageSize") Integer pageSize) {
        return logService.findSyslogLikeName(keywords, pageNum, pageSize);
    }

    @DeleteMapping("/delete")
    @ResponseBody
    public Boolean deleteSyslog(@RequestParam("id") String id) {
        int deleted = logService.deleteSyslog(id);
        return deleted > 0;
    }
}
